package widgets

import (
	"black_mamba/global"
	"gitee.com/wengo/windows_gui/listitemtemplate"
	"gitee.com/wengo/windows_gui/widget"
	"gitee.com/wengo/windows_gui/xc"
	"gitee.com/wengo/windows_gui/xcc"
)

func NewListBox(listBoxName, layoutName string, tableData map[string]interface{}) (listBox *widget.ListBox, hAdapter int){
	listBox = widget.NewListBoxByName(listBoxName)
	listBox.EnableMultiSel(false)
	listBox.SetItemHeightDefault(40, 40)
	listBox.SetDrawItemBkFlags(xcc.List_DrawItemBk_Flag_Nothing)
	listBox.SetItemTemplateXML(layoutName)

	template := listitemtemplate.NewListItemTemplate_LoadZipMem(xcc.ListItemTemp_Type_ListBox, global.BM_LAYOUTZIPFILE, layoutName, "")

	listBox.SetItemTemplate(template.Handle)

	hAdapter = xc.XAdTable_Create()

	listBox.BindAdapter(hAdapter)

	//// 填充头部
	//headers := tableData["headers"].([]string)
	//for _, header := range headers {
	//	xc.XAdTable_AddColumn(hAdapter, header)
	//}
	//
	//// 填充body
	//body := tableData["body"].([]map[string]string)
	//for _, data := range body {
	//	item := xc.XAdTable_AddItemText(hAdapter, "")
	//	for index, header := range headers {
	//		xc.XAdTable_SetItemText(hAdapter, item, index, data[header])
	//	}
	//}

	return
}

